package com.baizhi.staticx;

/**
 * 静态变量演示
 */
public class StaticVarDemo {
    int a; //实例变量/成员变量
    static int b; //静态变量

    //构造函数
    StaticVarDemo() {
        a++;
        b++;
    }

    public void show() {
        System.out.println("a=" + a + "\t" + "b=" + b);
    }
}

class StaticDemo02{
    public static void main(String[] args) {
        StaticVarDemo s1 = new StaticVarDemo();
        s1.show(); //a=1  b=1

        StaticVarDemo s2 = new StaticVarDemo();
        s2.show(); //a=1 b=2

        StaticVarDemo s3 = new StaticVarDemo();
        s3.show(); //a=1  b=3

        System.out.println(StaticVarDemo.b); //3
    }
}
